package com.sc.common.util;

import org.springframework.stereotype.Component;

import java.util.Random;

@Component
public class CodeUtil {
    private static Integer length = 5;
    private static Random rd = new Random();

    public static String getNumCode() {
        StringBuilder result = new StringBuilder(length);
        for (int i = 0; i < length; i++) {
            result.append(rd.nextInt(10));
        }
        return result.toString();
    }

    public static String getWordCode() {
        StringBuilder result = new StringBuilder(length);
        for (int i = 0; i < length; i++) {
            result.append((char) (rd.nextInt(26) + 65));
        }
        return result.toString();
    }

    public static String getMixCode() {
        StringBuilder result = new StringBuilder(length);
        for (int i = 0; i < length; i++) {
            int num = rd.nextInt(36) + 65;
            if (num > 90)
                result.append(num - 91);
            else
                result.append((char) num);
        }
        return result.toString();
    }

}
